<?php
/**
 * news.class
 *
 * script
 *
 * @version:	0.1a
 * @package:	global
 * @author:	alex_ez
 * @created:	28.01.2009 19:47:32
 *
 * @copyright:	(c) 2009 alex <qfox@ya.ru> yaroshevich aka alex_ez. All rights reserved.
 */

class news extends model
{
	protected $table = 'core_news';
	
	public function getAbove( $id )
	{
		$prev = 'SELECT * FROM `%1$s` WHERE `date` <= (SELECT `date` FROM `%1$s` WHERE id=%2$d) AND id<%2$d ORDER BY `date` DESC, id DESC LIMIT 1;';
		$next = 'SELECT * FROM `%1$s` WHERE `date` >= (SELECT `date` FROM `%1$s` WHERE id=%2$d) AND id>%2$d ORDER BY `date` ASC, id ASC LIMIT 1;';
		$r = array( );
		foreach( array( 'prev', 'next' ) as $k )
		{
			$sql = sprintf( $$k, $this ->table, $id );
			$r[$k] = $this ->db ->_row( $sql, 'id' );
		}
		return $r;
	}
}

?>